from flask import Blueprint, Flask, request
from VisaManager import vm

DPO2024 = Blueprint('DPO2024', __name__)
address: str = "TCPIP0::192.168.0.222::inst0::INSTR"
vm.add_resource(address)


@DPO2024.route('/DPO2024/TC000', methods=['POST'])
def TC000():
    '''
    状态控制
    '''
    arg1 = request.args.get('arg1')
    command_visa = f"ACQuire:STATE {arg1}"
    vm.write(address, command_visa)
    return "DPO2024 TC000 POST " + command_visa


@DPO2024.route('/DPO2024/TC001', methods=['POST'])
def TC001():
    '''
    模式配置
    '''
    arg1 = request.args.get('arg1')
    command_visa = f"ACQuire:STOPAfter {arg1}"
    vm.write(address, command_visa)
    return "DPO2024 TC001 POST " + command_visa


@DPO2024.route('/DPO2024/TC002', methods=['GET'])
def TC002():
    '''
    参数设置
    '''
    arg1 = request.args.get('arg1')
    command_visa = f"MEASUrement:IMMed:TYPe {arg1}"
    res = vm.query(address, command_visa)
    return res


@DPO2024.route('/DPO2024/TC003', methods=['GET'])
def TC003():
    '''
    参数获取
    '''
    command_visa = f"MEASUrement:IMMed:VALue?"
    res = vm.query(address, command_visa)
    return res


if __name__ == '__main__':
    app = Flask(__name__)
    app.register_blueprint(DPO2024)
    app.run()
